package cn.liuhuan1.entity;

import lombok.Data;

import java.io.Serializable;

/**
 * @author lzw
 * @since 2021-02-2021/2/2
 */
@Data
public class ReturnResult implements Serializable {
    /**
     * 错误代码
     */
    private String code = "200";

    /**
     * 错误信息
     */
    private String message = "success";

    /**
     * 登录信息（一般 储存在redis中 使用唯一id 作为token）
     */
    private String token;

    /**
     * 数据
     */
    private Object data;

    public ReturnResult(){}
    public ReturnResult(Object data){
        this.data = data;
    }

    public ReturnResult(Object data,String token){
        this.data = data;
        this.token = token;
    }

    public ReturnResult(String code,String message,Object data){
        this.data = data;
        this.message = message;
        this.code = code;
    }
    public static ReturnResult succes(){
        return new ReturnResult();
    }
    public static ReturnResult succes(Object data){
        return new ReturnResult(data);
    }

    public static ReturnResult succes(Object data,String token){
        return new ReturnResult(data,token);
    }

    public static ReturnResult error(String code,String message,Object data){
        return new ReturnResult(code,message,data);
    }

    public static ReturnResult error(String code,String message){
        return new ReturnResult(code,message);
    }
    public static ReturnResult error(){
        return new ReturnResult("500","error",null);
    }
}
